﻿<!DOCTYPE html>
<html>
<head>
    <title>WebApi示例</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link type="text/css" href="/js/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link type="text/css" href="/js/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" />
    <link type="text/css" href="/js/window/window.css" rel="stylesheet" />

    <script src="/js/jquery-1.7.1.min.js"></script>
    <script src="/js/window/window.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>

    <script type="text/javascript">
        function request(dom) {
            var p = $(dom).parent().prev().find("form").serialize();
            var url = $(dom).parent().prev().prev().prev().html();
            $.post(url, p, function (data) {
                $(dom).parent().next().html(data);
            }, 'text');
        }
    </script>

    <style type="text/css">
        body {
            padding: 10px;
        }
    </style>
</head>

<body>
    <div><span class="label label-info">服务器代码</span></div>
    <div class="cnblogs_code">
        <pre><span style="color: #0000ff;">namespace</span><span style="color: #000000;"> MixServer.Controller
{
    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
        <span style="color: #808080;">///</span><span style="color: #008000;"> WebApi控制器
    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> WebApiController : HttpController
    {
        </span><span style="color: #0000ff;">public</span><span style="color: #000000;"> JsonResult About()
        {
            </span><span style="color: #0000ff;">var</span> names = <span style="color: #0000ff;">typeof</span><span style="color: #000000;">(HttpController).Assembly.GetName();
            </span><span style="color: #0000ff;">return</span> Json(<span style="color: #0000ff;">new</span> { assembly = names.Name, version =<span style="color: #000000;"> names.Version.ToString() });
        }
        [HttpPost]
        </span><span style="color: #0000ff;">public</span> JsonResult Login(<span style="color: #0000ff;">string</span> account, <span style="color: #0000ff;">string</span><span style="color: #000000;"> password)
        {
            </span><span style="color: #0000ff;">return</span> Json(<span style="color: #0000ff;">new</span><span style="color: #000000;"> { account, password });
        }
    }
}</span></pre>
    </div>
    <p>&nbsp;</p>

    <div><span class="label label-info">客户端调用</span></div>
    <table class="table table-bordered table-striped">
        <thead>
            <tr>
                <th>路径</th>
                <th>方法</th>
                <th>参数</th>
                <th>操作</th>
                <td>返回</td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>/V2/WebApi/About</td>
                <td>GET/POST</td>
                <td>
                    <form></form>
                </td>
                <td>
                    <button class="btn btn-small" onclick="request(this);">请求</button>
                </td>
                <td></td>
            </tr>
            <tr>
                <td>/WebApi/Login</td>
                <td>POST</td>
                <td>
                    <form>
                        <label>账号</label>
                        <input type="text" name="account" value="xljiulang" />

                        <label>密码</label>
                        <input type="password" name="password" value="123456" />
                    </form>
                </td>
                <td>
                    <button class="btn btn-small" onclick="request(this);">请求</button>
                </td>
                <td></td>
            </tr>
            <tr>
                <td>/MyNamespace/RouteDataTest</td>
                <td>GET/POST</td>
                <td>
                    <form></form>
                </td>
                <td>
                    <button class="btn btn-small" onclick="request(this);">请求</button>
                </td>
                <td></td>
            </tr>
            <tr>
                <td>/MyNamespace/WebApi/RouteDataTest</td>
                <td>GET/POST</td>
                <td>
                    <form>
                        <label>value</label>
                        <input type="text" name="value" value="NetworkSocket" />
                    </form>
                </td>
                <td>
                    <button class="btn btn-small" onclick="request(this);">请求</button>
                </td>
                <td></td>
            </tr>
        </tbody>
    </table>
</body>
</html>
